<?php

function get_user_bonus($user_id = 0)
{
	if($user_id == 0)
	{
		$user_id=$_SESSION['user_id'];
	}
	
	$sql = "SELECT SUM(bt.type_money) AS bonus_value,COUNT(*) as bonus_count ".
			"FROM ".$GLOBALS['ecs']->table('user_bonus')." AS ub, ".
			$GLOBALS['ecs']->table('bonus_type') . " AS bt ".
			"WHERE ub.user_id = '$user_id' AND ub.bonus_type_id = bt.type_id AND ub.order_id = 0";
			
	$row = $GLOBALS['db']->getRow($sql);
	return $row;
}

function get_dyna_libs($theme,$tmp)
{
	$ext = end(explode('.', $tmp));
	$tmp = basename($tmp,".$ext");
	$sql = 'SELECT region,library,sort_order,id,number,type' . 
			' FROM ' . $GLOBALS['ecs']->table('template') . 
			" WHERE theme = '$theme' AND filename = '" . $tmp ."' AND type > 0 AND remarks=''".
			' ORDER BY region,library,sort_order';
	$res = $GLOBALS['db']->getAll($sql);
	
	$dyna_libs = array();
	foreach($res as $row) 
	{
		$dyna_libs[$row['region']][$row['library']][] = array(
			'id' => $row['id'],
			'number'	=> $row['number'],
			'type'		=> $row['type'],
		);
	}
	
	return $dyna_libs;
}

function show_message($content,$links = '',$hrefs = '',$type = 'info',$auto_redirect = true)
{
//	assign_template();
	
	$msg['content'] = $content;
	if(is_array($links) && is_array($hrefs))			//都是数组
	{
		if(!empty($links) && count($links) == count($hrefs))	//链接不为空，链接数等于连接数
		{
			foreach($links as $key =>$val)
			{
				$msg['url_info'][$val] = $hrefs[$key];
			}
			$msg['back_url'] = $hrefs['0'];
		}
	}
	else 
	{
		$link = empty($links) ? $GLOBALS['_LANG']['back_up_page'] : $links;
		$href = empty($hrefs) ? 'javascript:history.back()' 	  : $hrefs;
		$msg['url_info'][$link] = $href;
		$msg['back_rul'] = $href;
	}
	
	$msg['type'] = $type;

	$GLOBALS['smarty']->assign('auto_redirect',$auto_redirect);
	$GLOBALS['smarty']->assign('message',$msg);
	$GLOBALS['smarty']->display('message.dwt');
	exit;
}

function assign_template($ctype = '',$catlist = array())
{
	global $smarty;
	
	$smarty->assign('image_width',$GLOBALS['_CFG']['image_width']);
}

